<include file="../Public/header" />

		
		<link href="__PUBLIC__/themes/blue/layout.css" rel="stylesheet" type="text/css" />

		
		<script type="text/javascript" src="__PUBLIC__/js/tbox/tbox.js" ></script>
		<script type="text/javascript" src="__PUBLIC__/js/admin.js" ></script>
		<script type="text/javascript" src="__PUBLIC__/js/jquery-admin-box.js"></script>

		<!-- tbox用常量 -->
		<script>
			var THEME = "__THEME__";
			var APP    = "__APP__";
			var URL    = "__URL__";
			var PUBLIC = "../Public";
			var SITE_URL = "{*SITE_URL}";
		</script>
		
    </head>

    <body>
        <div id="container_s">
			<!-- 添加新的积分策略 BEGIN -->
            <form action="{:U('admin/System/doAddScore')}" method="post" onsubmit="return checkAdd();">
                <table class="tableborder" width="100%" id="new_score">
                    <tbody>
                        <tr class="top">
                            <td class="border" colspan="2"></td>
                        </tr>
                        <tr onclick="$('#new_score .cell').toggle();">
                            <th class="header" colspan="2">添加新的积分策略</th>
                        </tr>
                        <tr class="label cell">
                            <th>说明</th>
                            <th>设置</th>
                        </tr>
						<tr class="cell">
							<td class="altbg1">
								<b>动作名</b><br/>
								<span class="smalltxt">执行的动作名</span>
							</td>
							<td class="altbg2"><input id="action" style="width:250px;" name="action" class="txt mr10" value="" /><span id="tip"></span></td>
						</tr>
						<tr class="cell">
							<td class="altbg1">
								<b>动作别名</b><br/>
								<span class="smalltxt">执行的动作的别名</span>
							</td>
							<td class="altbg2"><input name="title" style="width:250px;" class="txt" value ="" /></td>
						</tr>
						<tr class="cell">
							<td class="altbg1">
								<b>提示信息</b>
								<br/>
								<span class="smalltxt">
									{actor}：动作发起者；{credit}：积分增减数量
								</span>
							</td>
							<td class="altbg2"><input name="info" style="width:250px;" class="txt" value ="" /></td>
						</tr>
						<tr class="cell">
							<td class="altbg1">
								<b>金币的增减量</b><br/>
								<span class="smalltxt">金币的增减量；正数为增加。负数为减少</span>
							</td>
							<td class="altbg2"><input name="score" style="width:250px;" class="txt" value ="" /></td>
						</tr>
						<tr class="cell">
							<td class="altbg1">
								<b>贡献值的增减量</b><br/>
								<span class="smalltxt">贡献值的增减量；正数为增加。负数为减少</span>
							</td>
							<td class="altbg2"><input name="exp" style="width:250px;" class="txt" value ="" /></td>
						</tr>
                        <tr class="cell">
                            <td class="footer" colspan="2">
                                <input type="submit" class="button mt10 mb10"  value="提交" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
			<!-- 添加新的积分策略 END -->

			<!-- 编辑积分策略 BEGIN -->
            <form method="post" id="form_all" name="form_all" action="{:U('admin/System/doSaveAllScore')}">
                <table class="tableborder" width="100%">
                    <tbody>
                        <tr class="top">
                            <td class="border" colspan="7"></td>
                        </tr>
                        <tr>
                            <th class="header" colspan="7">积分策略管理</th>
                        </tr>
                        <tr class="label">
							<th>ID</th>
						    <th>动作名</th>
							<th>动作的别名</th>
							<th>提示信息</th>
							<th>金币</th>
							<th>贡献值</th>
							<th>操作</th>
                        </tr>
                        <volist name="list" id="vo">
						<tr class="cell altbg1" id="list_{$vo['id']}">
							<td><label><input type="checkbox" class="score_admin_check" rel="0" dataId="{$vo['id']}"></label> {$vo['id']}</td>
							<td><input id="action_{$vo['id']}" type="text" class="large bLeftRequire" name="action[{$vo['id']}]" style="width:100px;" value="{$vo['key']}" /></td>
							<td><input id="title_{$vo['id']}" style="width:250px;" type="text" class="large bLeftRequire" name="title[{$vo['id']}]" style="width:100px;" value="{$vo['value']['title']}" /></td>
							<td><input id="info_{$vo['id']}" style="width:250px;" type="text" class="large bLeftRequire" name="info[{$vo['id']}]" style="width:100px;" value="{$vo['value']['info']}" /></td>
							<td><input id="score_{$vo['id']}" type="text" class="large bLeftRequire" name="score[{$vo['id']}]" style="width:100px;" value="{$vo['value']['score']}" /></td>
							<td><input id="exp_{$vo['id']}" type="text" class="large bLeftRequire" name="exp[{$vo['id']}]" style="width:100px;" value="{$vo['value']['exp']}" /></td>
							<td><input type="button" onclick="edit_one({$vo['id']});" value="保存" class="button" />
						</tr>
                        </volist>
                        <tr>
                            <td class="footer" colspan="7"> <input type="submit" value="保存全部" class="button" /></td>
                        </tr>
                    </tbody>
                </table>
            </form>
			<!-- 编辑积分策略 END -->
        </div>

		<div id="score_admin" style="display:none;">
			<a href="javascript:void(0)" onclick="deleteScore()">删除积分规则</a>
		</div>

		<script type="text/javascript">
			//加载前台管理工具
			$(function(){
				$.fn.admin({
					prefix:'score_',
					checkClass:'score_admin_check',
					hiddenId:'score_admin',
					lMinOffset:1,
					type:false,
					position:'right'
				});
			});

			//检测动作名是否可用
			$('#action').blur(function(){
				var act = $('#action').val();
				$.post("{:U('admin/System/isValidAction')}",{action:act},function(result){
					if(result == 1) {
						$('#tip').html('可用');
					}else {
						$('#tip').html('不可用');
					}
				});
			});
			
			//新建积分规则前检查
			function checkAdd() {
				if( $('#tip').html() == '可用' ) {
					;
				}else {
					$.tbox.no('标题不可用',"提示");
					setTimeout("$.tbox.close()",1500);
					return false;
				}
			}
			
			//编辑一条积分规则
			function edit_one(sid) {
				act = $('#action_'+sid).val();
				tit = $('#title_'+sid).val();
				inf = $('#info_'+sid).val();
				sco = $('#score_'+sid).val();
				exp = $('#exp_'+sid).val();
				$.post("{:U('admin/System/doSaveOneScore')}", {id:sid, action:act, title:tit, info:inf, score:sco, exp:exp}, function(result){
					if(result == 1) {
						$.tbox.yes('保存成功',"提示");
						setTimeout("$.tbox.close()",1500);
					}else{
						$.tbox.no('保存失败',"提示");
						setTimeout("$.tbox.close()",1500);
					}
				});
			}

			//删除积分规则
			function deleteScore() {
				if(confirm('删除后无法恢复！确认删除这些积分规则吗？')){
					$.post("{:U('admin/System/doDeleteScore')}", {id:$.fn.getData('score_')}, function(result){
						if(result == 1) {
							$.tbox.yes('删除成功',"提示");
							setTimeout("$.tbox.close()",1500);
							$.each($.fn.getData('score_'),function(i,n){
								$("#list_"+n).remove();
							});
							$('#score_admin_box').hide();
						}else{
							$.tbox.no('删除失败',"提示");
							setTimeout("$.tbox.close()",1500);
						}
					});
				}
			}

        </script>

    </body>
</html>